package cn.gson.crm.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.Backplan;
import cn.gson.crm.model.pojo.ConstactOrder;
import cn.gson.crm.model.pojo.OrderResult;
import cn.gson.crm.model.vo.BackplanVO;
import cn.gson.crm.service.BackPlanService;

@Controller
public class BackPlanControl {
	@Autowired
	private BackPlanService bService;
	
	@GetMapping("/getAllBackPlan")
	@ResponseBody
	public Map getAllBackPlan(int page,int rows) {
		Map map = new HashMap<>();
		List<BackplanVO> list = bService.getAllBackPlan(page, rows);
		Long count = bService.count();
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
	
	@GetMapping("/getBackPlanById")
	@ResponseBody
	public BackplanVO getBackPlanById(Long bpId) {
		return bService.getBackPlanById(bpId);
	}
	
	@GetMapping("/deleteBackPlan")
	@ResponseBody
	public OrderResult deleteBackPlan(Long bpId) {
		try {
			bService.deleteBackPlan(bpId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@PostMapping("/addNewBackPlan")
	@ResponseBody
	public OrderResult addNewBackPlan(Backplan bp) {
		System.out.println(bp.getBpId()+"abc");
		try {
			bService.addSgf(bp);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@PostMapping("/editNewBackPlan")
	@ResponseBody
	public OrderResult editNewBackPlan(Backplan bp,Long bpId) {
		System.out.println(bpId+"22");
		try {
			bService.editSgf(bp, bpId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@GetMapping("/toBackPlan")
	public String toBackPlan() {
		return "zj/backPlan";
	}
}
